package exatrez.config;

import able.guice.AbleModule;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Provider;
import exatrez.quartz.AdminSchedulerManager;
import exatrez.quartz.GuiceJobFactory;
import exatrez.quartz.PtaskSchedulerManager;
import exatrez.quartz.SchedulerManager;
import exatrez.quartz.Visit3SchedulerManager;
import exatrez.quartz.VisitSchedulerManager;
import exatrez.stripes.ableStripesModule;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.spi.JobFactory;


public class ableModule extends AbleModule {
    public ableModule() {
        super(new ableConfiguration(), new ableStripesModule());
    }

    @Override
    public void configure(Binder binder) {
        super.configure(binder);
        binder.bind(JobFactory.class).to(GuiceJobFactory.class);
        binder.bind(Scheduler.class).toProvider(new Provider<Scheduler>() {

            @Inject JobFactory jobFactory;

            public Scheduler get() {
                try {
                    Scheduler sc = StdSchedulerFactory.getDefaultScheduler();
                    sc.setJobFactory(jobFactory);
                    return sc;
                } catch (SchedulerException ex) {
                    throw new RuntimeException(ex);
                }
            }
            
        });
        
        binder.bind(SchedulerManager.class);
        binder.bind(PtaskSchedulerManager.class);
//        binder.bind(VisitSchedulerManager.class);
        binder.bind(Visit3SchedulerManager.class);
        binder.bind(AdminSchedulerManager.class);
    }
}
